package com.ghd.dataviz.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author ：ghd
 * @date ：Created in 2020-04-04 22:03
 * @description：
 * @modified By：
 * @version: $
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ghd.dataviz.controller"))
                .paths(PathSelectors.any())
                .build()
                    .securityContexts(Lists.newArrayList(SecurityContext.builder()
                            .forPaths(PathSelectors.regex("/.*"))
                            .build()))
                    .securitySchemes(Lists.newArrayList(
                            new ApiKey("BearerToken", "token", "header")))
                    .apiInfo(new ApiInfoBuilder()
                        .title("ghd-dataviz-admin api")
                        .description("数据可视化框架API")
                        .version("0.1")
                        .contact(new Contact("ghd","","guo2184@163.com"))
                        .license("GNU General Public License v3.0")
                        .licenseUrl("https://gitee.com/guo2184/ghd-dataviz/blob/dev/LICENSE")
                        .build());
    }
}
